{
  "nbformat": 4,
  "nbformat_minor": 0,
  "metadata": {
    "colab": {
      "name": "sentence_extractor.ipynb",
      "version": "0.3.2",
      "provenance": [],
      "collapsed_sections": [],
      "include_colab_link": true
    },
    "kernelspec": {
      "name": "python3",
      "display_name": "Python 3"
    }
  },
  "cells": [
    {
      "cell_type": "markdown",
      "metadata": {
        "id": "view-in-github",
        "colab_type": "text"
      },
      "source": [
        "<a href=\"https://colab.research.google.com/github/gdoteof/neuralnet_stuff/blob/master/sentence_extractor.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
      ]
    },
    {
      "metadata": {
        "id": "rId6DMLNmBp3",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "strs = []\n",
        "strs.append(\"hi \\n\\n my name is \\n geoff \\n and i am \\n\\n here to say\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "nc_nlxxZtI7p",
        "colab_type": "code",
        "outputId": "703e00c2-381f-4bd9-a401-7f15507ed9eb",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 145
        }
      },
      "cell_type": "code",
      "source": [
        "for x in strs: print(x)"
      ],
      "execution_count": 3,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "hi \n",
            "\n",
            " my name is \n",
            " geoff \n",
            " and i am \n",
            "\n",
            " here to say\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "eH5CzhcjtUgl",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "t = []\n",
        "t.append(\"my name is \\ngeoff \\nand i am\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "0Q6X8H2DtouN",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "strs.append(\"my name is geoff\")\n",
        "t.append(None)"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "1DLRtC5FtwyT",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        "strs.append(\"my name is geoff\\n\\n\")\n",
        "t.append(\"my name is geoff\")"
      ],
      "execution_count": 0,
      "outputs": []
    },
    {
      "metadata": {
        "id": "XKtlqhIPupfK",
        "colab_type": "code",
        "outputId": "39813209-3584-495b-86a0-a05efcb0811b",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 35
        }
      },
      "cell_type": "code",
      "source": [
        "print(zip(strs,t))"
      ],
      "execution_count": 7,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "<zip object at 0x7f065d139b88>\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "dn5g3zUQurfY",
        "colab_type": "code",
        "outputId": "5f52ad93-d918-48e6-fef8-1b3531600887",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 72
        }
      },
      "cell_type": "code",
      "source": [
        "for x in zip(strs,t):\n",
        "  print(x)"
      ],
      "execution_count": 8,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "('hi \\n\\n my name is \\n geoff \\n and i am \\n\\n here to say', 'my name is \\ngeoff \\nand i am')\n",
            "('my name is geoff', None)\n",
            "('my name is geoff\\n\\n', 'my name is geoff')\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "L1sfuqcOuwO4",
        "colab_type": "code",
        "colab": {
          "base_uri": "https://localhost:8080/",
          "height": 835
        },
        "outputId": "d1fdf90c-bfa2-45a3-c938-0fe4f17eb890"
      },
      "cell_type": "code",
      "source": [
        "def extract_fc(words, min_length=6):\n",
        "  print(\"words = \", words)\n",
        "  buffer = []\n",
        "  last   = None\n",
        "  for w in words:\n",
        "    if w != \"\\n\\n\":\n",
        "      buffer.append(w)\n",
        "    else:\n",
        "      if  len(buffer) >= min_length:\n",
        "        return \" \".join(buffer)\n",
        "      else:\n",
        "          buffer = []\n",
        "  return None\n",
        "      \n",
        "      \n",
        "def test():\n",
        "  for x,y in zip(strs,t):\n",
        "    print(\"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\")\n",
        "    ans = extract_fc(x.split(\" \"))\n",
        "    if(ans==y):\n",
        "      print(\"PASS\")\n",
        "    else:\n",
        "      print(\"FAIL!!!!!!!!!!!!!!!!!!!!!!\")\n",
        "      print(\"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\")\n",
        "      print(\"TEST STRING\\n==========\")\n",
        "      print(x)\n",
        "      print(\"%%%%%%%%%%%%%%%%%%%%%%%\\nEXPECTED\\n==========\")\n",
        "      print(y)\n",
        "      print(\"ACTUAL\\n==========\")\n",
        "      print(ans)\n",
        "    \n",
        "test()"
      ],
      "execution_count": 27,
      "outputs": [
        {
          "output_type": "stream",
          "text": [
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
            "words =  ['hi', '\\n\\n', 'my', 'name', 'is', '\\n', 'geoff', '\\n', 'and', 'i', 'am', '\\n\\n', 'here', 'to', 'say']\n",
            "FAIL!!!!!!!!!!!!!!!!!!!!!!\n",
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
            "TEST STRING\n",
            "==========\n",
            "hi \n",
            "\n",
            " my name is \n",
            " geoff \n",
            " and i am \n",
            "\n",
            " here to say\n",
            "%%%%%%%%%%%%%%%%%%%%%%%\n",
            "EXPECTED\n",
            "==========\n",
            "my name is \n",
            "geoff \n",
            "and i am\n",
            "ACTUAL\n",
            "==========\n",
            "my name is \n",
            " geoff \n",
            " and i am\n",
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
            "words =  ['my', 'name', 'is', 'geoff']\n",
            "Leaving with len: 4 and buffer: ['my', 'name', 'is', 'geoff']\n",
            "PASS\n",
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
            "words =  ['my', 'name', 'is', 'geoff\\n\\n']\n",
            "Leaving with len: 4 and buffer: ['my', 'name', 'is', 'geoff\\n\\n']\n",
            "FAIL!!!!!!!!!!!!!!!!!!!!!!\n",
            "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%\n",
            "TEST STRING\n",
            "==========\n",
            "my name is geoff\n",
            "\n",
            "\n",
            "%%%%%%%%%%%%%%%%%%%%%%%\n",
            "EXPECTED\n",
            "==========\n",
            "my name is geoff\n",
            "ACTUAL\n",
            "==========\n",
            "None\n"
          ],
          "name": "stdout"
        }
      ]
    },
    {
      "metadata": {
        "id": "swUk4LiWjkbX",
        "colab_type": "code",
        "colab": {}
      },
      "cell_type": "code",
      "source": [
        ""
      ],
      "execution_count": 0,
      "outputs": []
    }
  ]
}